package com.zl.learning.thread.thread_daemon;

import java.io.*;

/**
 * Created by zhaolei on 2017/4/17.
 */
public class DaemonThread implements Runnable {
    @Override
    public void run() {
        System.out.print("进入守护线程"+Thread.currentThread().getName());
        try {
            writeToFile();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("退出守护线程"+Thread.currentThread().getName());
    }

    private void writeToFile() throws IOException {
        File fileName = new File("daemon.txt");
        OutputStream os = new FileOutputStream(fileName,true);
        int count =0;
        while(count <99){
            os.write(("\r\nword"+count).getBytes());
            System.out.println("写入了"+count);
            count ++;
        }
    }
}
